import { EggAppConfig, EggAppInfo, PowerPartial } from 'egg';
import { SATISFY_SUFFIX } from '../constants/image';

const {
  ALI_NODE_APP_ID,
  ALI_NODE_SECRET
} = process.env;

export default (appInfo: EggAppInfo) => {
  const config: PowerPartial<EggAppConfig> = {};

  // override config from framework / plugin
  // use for cookie sign key, should change to your own and keep security
  config.keys = `${appInfo.name}_1625282849764_4292`;

  // add your egg config in here
  config.middleware = [];

  // add your special config in here
  const bizConfig = {
    sourceUrl: `https://github.com/eggjs/examples/tree/master/${appInfo.name}`,
  };

  // 取消安全证书验证
  config.security = {
    csrf: {
      enable: false,
    },
    // domainWhiteList: ["*"], // 白名单
  };

  config.cors = {
    origin: '*', // 跨任何域
    allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH,OPTIONS', // 被允许的请求方式
  };

  config.passportJwt = {
    secret: process.env.TOKEN_SECRET,
  };

  config.validate = {
    convert: true,
  };

  config.middleware = ['errorHandler'];

  config.multipart = {
    whitelist: SATISFY_SUFFIX
  };

  config.alinode = {
    appid: ALI_NODE_APP_ID,
    secret: ALI_NODE_SECRET
  };

  // the return config will combines to EggAppConfig
  return {
    ...config,
    ...bizConfig,
  };
};
